"""获取配置信息"""

__all__ = ["GCF"]

from pathlib import Path

import yaml

from models.config import GlobalConfig


def _get_config(config_path: Path) -> GlobalConfig:
    assert config_path.exists(), f'{config_path} 配置文件不存在'

    try:
        with open(config_path, 'r', encoding='utf-8') as f:
            data = yaml.safe_load(f)
    except:
        assert False, f'{config_path} 加载失败'

    match config_path.name:
        case 'application.yaml':
            return GlobalConfig(**data)
        case _:
            assert False, f'{config_path} 未能匹配到数据模型类'


GCF: GlobalConfig = _get_config(Path(__file__).parent.parent / 'assets/application.yaml')
